home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14047 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character string
  5. Date: 11 Apr 1996 07:50 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <11APR199607504516@erich.triumf.ca>
  9. References: <4kil74$8i7@Tandem1.opennet.net.au>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4kil74$8i7@Tandem1.opennet.net.au>, george@opennet.net.au (Kenneth H Smith) writes...
  14. >How do I do a similar statement in C to the Pascal code:
  15. >If Ch IN ['a','A'] THEN
  16. >I want to execute a piece of code when a particular character is entered
  17. >from the keyboard.
  18. >I know I can use if (ch=='a') && (ch=='A') but was looking for something
  19. >a little more ellegant.
  20.  
  21. char ch;
  22. switch (tolower(ch)) {
  23.     case 'a':
  24.               /* do 'a' task  */
  25.         break;
  26.     case 'b':
  27.               /* do 'b' task  */
  28.         break;
  29.     ....
  30.     default:
  31.         /* no valid choice... */
  32.     }
  33.  
  34. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  35. Internet: bennett@triumf.ca         | of one another only when one can be
  36. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  37. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  38. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  39. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  40.  
  41.  
  42.  
  43.